package com.java.simple.study.jvm.classloader;

import java.util.concurrent.TimeUnit;

/**
 * @author zhoujunlin
 * @date 2022年05月15日 21:24
 * @desc
 */
public class DeadThreadTest {

    public static void main(String[] args) {
        Runnable r = () -> {
            System.out.println(Thread.currentThread().getName() + "开始");
            DeadThread deadThread = new DeadThread();
            System.out.println(Thread.currentThread().getName() + "结束");
        };
        Thread t1 = new Thread(r, "线程1");
        Thread t2 = new Thread(r, "线程2");
        t1.start();
        t2.start();
    }

}


class DeadThread {
    static {
        // 验证static方法有锁且只可被初始化一次
        if (true) {
            System.out.println(Thread.currentThread().getName() + "初始化该类");
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}